using FSM.IBll; 
using FSM.Model; 
using FSM.Web.Models; 
using FSM.Web.Models.Fileter; 
using Microsoft.AspNetCore.Mvc; 
using System; 
using System.Collections.Generic; 
using System.Linq; 
using System.Threading.Tasks; 
 
namespace FSM.Web.Controllers 
{ 
    public class SysParamSubController : BaseController 
    { 
        #region 模块 
 
        private readonly DataResultModel drm; 
 
        private readonly ISysParamSubBll _bll; 
 
        #endregion 
 
        #region 构造函数 
 
        public SysParamSubController(ISysParamSubBll bll) 
        { 
            _bll = bll; 
            drm = new DataResultModel(); 
            ModuleNo = ""; 
        } 
 
        #endregion 
 
        #region 功能 
 
        public IActionResult Index() 
        { 
            return View(); 
        } 
 
        [HttpPost] 
        [ResultExceptionFilter] 
        [OperateAuthorize("0106", "Query")] 
        public JsonResult Get(int id) 
        { 
            sys_param_sub model = _bll.Get(id); 
            drm.success = true; 
            drm.data = model; 
            return drm.ToJson(); 
        } 
 
        /// <summary> 
        /// 查询 
        /// </summary> 
        /// <param name="param_no">参数编号</param> 
        /// <param name="sub_name">子参数显示值</param> 
        /// <param name="sub_value">子参数保存值</param> 
        [HttpPost] 
        [ResultExceptionFilter] 
        [OperateAuthorize("0106", "Query")] 
        public JsonResult List(int? param_no, string sub_name, string sub_value, int? page = 1, int? page_size = 30) 
        { 
            Tuple<List<sys_param_sub>, int> result = _bll.ListPagin(param_no, sub_name, sub_value, page.Value, page_size.Value); 
            drm.success = true; 
            drm.data = result.Item1; 
            drm.total = result.Item2; 
            return new JsonResult(drm); 
        } 
 
        /// <summary> 
        /// 新增 
        /// </summary> 
        /// <param name="model">实体</param> 
        /// <returns></returns> 
        [HttpPost] 
        [ResultExceptionFilter] 
        [OperateAuthorize("0106", "Add")] 
        public JsonResult Insert(sys_param_sub model) 
        { 
            model.creater = AuthencationHelper.GetLoginUserNo(User); 
            bool success = _bll.Insert(model); 
            drm.success = success; 
            drm.data = model; 
            return new JsonResult(drm); 
        } 
 
        /// <summary> 
        /// 更新 
        /// </summary> 
        /// <param name="model">实体</param> 
        /// <returns></returns> 
        [HttpPost] 
        [ResultExceptionFilter] 
        [OperateAuthorize("0106", "Edit")] 
        public JsonResult Update(sys_param_sub model) 
        { 
            model.editer = AuthencationHelper.GetLoginUserNo(User); 
            bool success = _bll.Update(model); 
            drm.success = success; 
            drm.data = model; 
            return new JsonResult(drm); 
        } 
 
        /// <summary> 
        /// 删除 
        /// </summary> 
        /// <param name="sub_no">键值</param> 
        /// <returns></returns> 
        [HttpPost] 
        [ResultExceptionFilter] 
        [OperateAuthorize("0106", "Delete")] 
        public JsonResult Delete(string sub_nos) 
        {
            int[] arr = sub_nos.Split(',').Select(p => Convert.ToInt32(p)).ToArray();
            bool success = _bll.Delete(arr); 
            drm.success = success; 
            return new JsonResult(drm); 
        } 
 
        #endregion 
    } 
} 
